package main;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.MIDlet;

public class MainMidlet extends MIDlet {
	// PlayingCanvas playingCanvas;

	DrawingCanvas drawingCanvas;
	ColorCanvas colorCanvas;
	MenuCanvas menuCanvas;

	public void startApp() {
		Res.init();
		// drawingCanvas = new DrawingCanvas(this, 32, 32);
		colorCanvas = new ColorCanvas(this);
		menuCanvas = new MenuCanvas(this);
		show(menuCanvas);
		/*
		 * if(drawingCanvas.existingSavedGame()){ drawingCanvas.loadGame(); }
		 */
	}

	public void starGame(boolean soundOn) {

	}

	public void pauseApp() {

	}

	public void destroyApp(boolean unconditional) {
		if (drawingCanvas != null) {
			drawingCanvas.stop();
			drawingCanvas.saveGame(true);
		}
		// drawingCanvas.saveGame();
	}

	public void show(Displayable d) {

		Display.getDisplay(this).setCurrent(d);
	}

	public void loadDrawingCanvas() {
		if (drawingCanvas == null) {
			drawingCanvas = new DrawingCanvas(this, 0, 0);
			drawingCanvas.start();
		}
		drawingCanvas.loadGame(false);
	}

	public void saveDrawingCanvas() {
		if (drawingCanvas != null) {
			drawingCanvas.saveGame(false);
		}
	}

	public void newDrawingCanvas(int w, int h) {
		if (drawingCanvas != null) {
			drawingCanvas.stop();
		}
		drawingCanvas = new DrawingCanvas(this, w, h);
		drawingCanvas.start();
	}

	public void showDrawingCanvas() {
		if (drawingCanvas == null) {
			if (!DrawingCanvas.existingSavedGame(true)) {
				return;
			}
			drawingCanvas = new DrawingCanvas(this, 0, 0);
			drawingCanvas.loadGame(true);
			drawingCanvas.start();
		}
		show(drawingCanvas);
	}

	public void showMenuCanvas() {
		show(menuCanvas);
	}

	public void showColorCanvas(ColorHandler colorHandler) {
		colorCanvas.setChooser(Display.getDisplay(this).getCurrent(), colorHandler);
		show(colorCanvas);
	}

	public void showMenu() {
		show(new ImageCanvas(this, drawingCanvas));
	}
	public void showMovingCanvas() {
		show(new MoveImageCanvas(this, drawingCanvas));
	}
/*
	public void setColor(int color) {
		drawingCanvas.setColor(color);
	}*/
}
